1. Field of the Present Invention
The present invention is related to the field of computer software and more particularly to a method and system for monitoring memory allocation in a computer system.
2. History of Related Art
In the field of computer software, execution profiling tools are commonly used to identify frequently executed code and calling sequences. By monitoring these events, system programmers can focus their attention on the code paths likely to have the greatest impact on overall performance. Typically, these tools are implemented with time based sampling techniques in which the currently executing code is observed at regular intervals. Sampling is generally required because a complete trace of the execution of every bit of code in a program would reduce the performance beyond a feasible level and would result in an unwieldy amount of data. While, such tools are commonly available for the purposes of monitoring software execution, there is a lack of adequate tools for monitoring memory allocation performance. In high level applications programming languages like C/C++, memory management is handled by the programmer. When memory management is directly handled by the programmer, a tool designed to specifically track memory allocation might be considered as less than critical. In other programming languages, such as the Java programming language, the allocation of memory and, to an even greater extent, the deallocation of memory is largely beyond the programmer""s control. In Java, allocation of memory is achieved by the creation of new objects. (Even array types are treated as objects in the Java programming language). While delegating the allocation of memory to objects in the Java programming languages reduces premature deallocation of memory (corrupted pointers) and the incomplete deallocation (memory leaks), it does make it more difficult for the programmer to analyze any memory allocation problems that the system may produce. Even in languages like C++, the extensive use of pre-existing software libraries removes much of the memory allocation activity from the application programmer""s direct control. It would therefore be desirable to implement a tool suitable for monitoring memory allocation performance of a computer system. It would be further desirable if the performance monitoring tool were capable of monitoring allocation of memory by a high level programming language such as the Java programming language. It would be further desirable if the implemented solution did not significantly increase the complexity of the software system.
The problem identified above is addressed, in large part, by a method, system, and computer program product for profiling memory allocation in a data processing system. The method includes, upon receiving a memory allocation request, profiling the memory allocation request to determine a prescribed set of characteristics associated with the request. The profiled set of characteristics is the stored for subsequent review. In one embodiment, the profiled memory allocation request is selectively chosen from a set of memory allocation requests on the basis of a memory allocation sampling criterion. The sampling criterion may be based upon the size of the memory block requested in the memory allocation request in one embodiment. In an alternative embodiment, the sampling criterion is the based upon the number of memory allocation requests. In an embodiment with multiple memory allocation routines, the memory allocation request may be of a first memory allocation routine type and the sampling criterion may be based upon the number of memory allocation requests of the first type. In one embodiment, the set of characteristics monitored by the application program includes the calling sequence that resulted in the memory allocation request. In one embodiment, the memory allocation request may be initiated by an application program written in the Java programming language and the memory allocation request is handled by a Java Virtual Machine.
The invention further contemplates a data processing system and an associated computer program product. The computer program product is a computer readable media including a set of instructions executable by a data processing system and suitable for profiling memory allocation requests. The set of recorded instructions includes sampling means for determining if a memory allocation request satisfies a profiling criterion and profiling means that are responsive to determining that the memory allocation request fulfills the profiling criterion. The profiling means is suitable for determining a set of characteristics associated with the memory allocation request. The set of instructions further includes means for storing the profiled set of characteristics for subsequent review. In one embodiment, the sampling means includes means for counting the number of memory allocation requests since a preceding memory allocation request was profiled and profiling the current memory allocation request if the number exceeds a specified threshold. In an alternative embodiment, the sampling means comprise means for determining the size of memory requested in the memory allocation request and profiling the memory request if the size exceeds a specified threshold. In another embodiment, the sampling means comprise means for determining the cumulative size of memory allocated since the profiling means was previously invoked. The profiling means includes means for determining the process, thread, and calling sequence that initiated the memory allocation request. In one embodiment, the profiling means are included in a memory allocation routine within a Java Virtual Machine.